﻿<%@ WebHandler Language="C#" Class="Check" %>

using System;
using System.Web;
using System.Reflection;
using System.Web.SessionState;
using Dos.Model;

public class Check : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        if (context.Request["method"] != null)
        {
            lock (this)
            {
                MethodInfo mi = this.GetType().GetMethod(context.Request["method"]);
                mi.Invoke(this, new object[] { context });
            }
        }
    }

    public void Login(HttpContext ctxt)
    {
        int res = -1;
        HttpRequest req = ctxt.Request;
        if (!string.IsNullOrEmpty(req["acc"]) && !string.IsNullOrEmpty(req["pwd"]))
        {
            string __pwd = Tools.MD5(req["pwd"]);
            my_admin u = DB.Context.From<my_admin>().Select(s => new { s.id, s.username, s.password, s.phone, s.email, s.true_name, s.type }).Where(w => w.username.Equals(req["acc"]) && w.password.Equals(__pwd)).First();
            if (u != null)
            {
                ctxt.Session["User"] = u;
                res = 1;
            }
            else
                res = 0;
        }
        ctxt.Response.Write(res);
    }


    public bool IsReusable
    {
        get { return false; }
    }

}